package cn.yiyuan.org.service.impl;

import cn.yiyuan.base.until.PageInfo;
import cn.yiyuan.org.domain.Dep;
import cn.yiyuan.org.mapper.DepMapper;
import cn.yiyuan.org.query.DepQuery;
import cn.yiyuan.org.service.IDepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

/**
 * @user m
 * @project system
 * @date 2023-10-27
 * @package cn.yiyuan.org.service.impl
 */
//事务
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
@Service
public class DepServiceImpl implements IDepService {
    @Autowired
    private DepMapper depMapper;

    @Override
    @Transactional
    public void insert(Dep dep) {
        depMapper.insert(dep);
    }

    @Override
    @Transactional
    public void delete(Serializable id) {
        depMapper.delete(id);
    }

    @Override
    @Transactional
    public void update(Dep dep) {
        depMapper.update(dep);
    }

    @Override
    public List<Dep> getAll() {
        return depMapper.getAll();
    }

    @Override
    public Dep getById(Serializable id) {
        return depMapper.getById(id);
    }

    @Override
    public PageInfo<Dep> queryPage(DepQuery depQuery) {
        // 查询总条数
        Long total = depMapper.queryTotal(depQuery);
        //查询分页  数据
        //享元模式
        if (total != 0) {
            List<Dep> list = depMapper.queryPage(depQuery);
            return new PageInfo<Dep>(total, list);
        }
        return new PageInfo<Dep>();
    }


}
